<div class="span12">	
    <ul class="breadcrumb">
        <li class="previous"><a href="<?php echo SITE_URL; ?>">Home /</a></li>
        <li class="previous">
            <?php
            if ($classcoursetype == "classes") {
                echo CHtml::link($classDetails->class_titile . ' /', $this->createAbsoluteUrl('classes/viewClass/', array('id' => $classDetails->id)));
            } else {
                echo CHtml::link($classDetails->course_titile . ' /', $this->createAbsoluteUrl('courses/viewcourse/', array('id' => $classDetails->id)));
            }
            ?></li>
        <li class="disable"><a href="javascript:void(0);"> Recommend a friend</a></li>
    </ul>
    <div class="common">
        <div class="whiteBg blueBor padding20px">
            <h5 class="fnt-size20">Recommend A friend</h5>
        </div>
    </div> <div class="whiteBg blueBor padding20px" id="frd_success" style="display: none;">
        <div class="formElements">
            <div class="common"><div id="formResult" style="color:#66bc7d"></div></div></div></div>
    <div class="common">        
        <?php
        $form = $this->beginWidget('CActiveForm', array(
            'id' => 'recommend-to-user-form',
            'enableAjaxValidation' => false,
            'htmlOptions' => array(
                'onsubmit' => "return false;", /* Disable normal form submit */
            ),
                ));
        ?>
        <fieldset>
            <div class="createBox addmarginB20">
                <h4 class="txtfff fnt-size20"><?php
        if ($classcoursetype == "classes") {
            echo $classDetails->class_titile;
        } else {
            echo $classDetails->course_titile;
        }
        ?></h4>
                <div class="padding20px">
                    <div class="formElements">
                        <div class="col-3">
                            <h5 class="txttTransformNorml txt737 fntweghtNml addpaddingB5 fnt-size20 font-georgia">User Details</h5>
                            <div class="height1px dash-borB addmarginB30"></div>
                            <div class="common">
                                <div class="col col1">
                                    <input name="classcoursetype" type="hidden" value="<?php echo $classcoursetype; ?>">
                                    <?php if ($classcoursetype == "classes") { ?>
                                        <?php echo $form->hiddenField($recommendFromUser, 'classes_id', array('value' => $classDetails->id)); ?>
                                    <?php } else { ?>
                                        <?php echo $form->hiddenField($recommendFromUser, 'courses_id', array('value' => $classDetails->id)); ?>
                                    <?php } ?>
                                    <?php echo $form->labelEx($recommendFromUser, 'from_name'); ?>
                                    <?php echo $form->textField($recommendFromUser, 'from_name', array('maxlength' => 45, 'class' => 'field requiredfield', 'id' => 'from_name_1', 'value' => ($profileDetails != '') ? $profileDetails->first_name : '')); ?>
                                    <div class="errorMessage" style="display: none;" id="error_from_name_1">Name cannot be blank.</div>
                                </div>
                                <div class="col col2">
                                    <?php echo $form->labelEx($recommendFromUser, 'from_email'); ?>
                                    <?php echo $form->textField($recommendFromUser, 'from_email', array('maxlength' => 45, 'class' => 'field requiredfield email', 'id' => 'from_email_1', 'value' => ($profileDetails != '') ? $profileDetails->user->username : '')); ?>
                                    <div class="errorMessage" style="display: none;" id="error_email_1">Email cannot be blank.</div>
                                    <div class="errorMessage" id="error_email_1"></div>
                                </div>
                                <div class="col col3">
                                    <?php echo $form->labelEx($recommendFromUser, 'from_phone_no'); ?>
                                    <?php echo $form->textField($recommendFromUser, 'from_phone_no', array('maxlength' => 12, 'class' => 'field ', 'value' => ($profileDetails != '') ? $profileDetails->phone : '')); ?>
                                    <?php echo $form->error($recommendFromUser, 'from_phone_no'); ?>
                                </div>
                                <div class="clear"></div>
                            </div>
                            <h5 class="txttTransformNorml txt737 fntweghtNml addpaddingB5 fnt-size20 font-georgia">Friend Details</h5>
                            <!--repeat this div on add more click-->

                            <div>
                                <div class="height1px dash-borB addmarginB30"></div>
                                <div class="addmoreFriend">
                                    <div class="common">
                                        <div class="col col1">
                                            <label><?php echo $form->labelEx($model, 'to_name'); ?></label>
                                            <?php echo $form->textField($model, 'to_name[]', array('maxlength' => 45, 'class' => 'field requiredfield', 'id' => 'to_name_0')); ?>
                                            <div class="errorMessage" style="display: none;" id="error_to_name_0">Name cannot be blank.</div>
                                        </div>
                                        <div class="col col2">
                                            <label><?php echo $form->labelEx($model, 'to_email'); ?></label>
                                            <?php echo $form->textField($model, 'to_email[]', array('maxlength' => 45, 'class' => 'field requiredfield email', 'id' => 'to_email_0')); ?>
                                            <div class="errorMessage" style="display: none;" id="error_to_email_0">Email cannot be blank.</div>
                                            <div class="errorMessage"  id="error_to_email_0"></div>
                                        </div>
                                        <div class="col col3">
                                            <label><?php echo $form->labelEx($model, 'to_phone_no'); ?></label>
                                            <?php echo $form->textField($model, 'to_phone_no[]', array('maxlength' => 12, 'class' => 'field')); ?>
                                            <?php echo $form->error($model, 'to_phone_no'); ?>
                                        </div>
                                        <div class="clear"></div>

                                    </div>
                                </div>
                                <p class="alignR"><a href="javascript:void(0)" onclick="addMoreFrienddetails();">+ Add more</a></p>

                                <div class="common">
                                    <label>Enter Message for Friend </label>
                                    <?php echo $form->textArea($model, 'to_message_text'); ?>
                                    <div class="clear"></div>
                                </div>
                            </div>
                            <!--repeat this div on add more click-->


                            <!--add more buuton-->                                      


                        </div>

                    </div>
                </div>

            </div>

            <div class="common">
                <p class="alignR remmarginB">
                    <span id="AjaxLoader"  style="display:none;"><img src="<?php echo ThemePath(); ?>/images/ajax-loader-mini.gif"></img></span>
                    <?php echo GxHtml::submitButton(Yii::t('app', 'Recommend'), array('id' => 'recommend_to_frd', 'class' => 'btn')); ?></p>
            </div>
        </fieldset>
        <?php $this->endWidget(); ?>
    </div>

</div>

<script>


    window.onload = pre_loader;
    function pre_loader() {
        javascript:document.getElementById('contentCntr').removeAttribute('id');
    }

    var counter = 1;
    function addMoreFrienddetails() {
        counter = counter + 1;
        $(".addmoreFriend").append('<div id="remove_addmoreFriend' + counter + '"><div class="common">\n\
<div class="col col1"><label class="error required" for="RecommendToUser_to_name">Name <span class="required">*</span></label>\n\
 <input maxlength="45" class="field requiredfield" name="RecommendToUser[to_name][]" id="to_name_' + counter + '" type="text" >\n\
<div class="errorMessage" style="display:none;" id="error_to_name_' + counter + '">Name cannot be blank.</div>  </div><div class="col col2">\n\
<label class="error required" for="RecommendToUser_to_email">Email <span class="required">*</span></label>\n\
<input maxlength="45" class="field requiredfield email" name="RecommendToUser[to_email][]" id="to_email_' + counter + '" type="text" >\n\
<div class="errorMessage" style="display:none;" id="error_to_email_' + counter + '">Email cannot be blank.</div>\n\
<div class="errorMessage"id="error_to_email_' + counter + '"></div> </div>\n\
<div class="col col3"><label for="RecommendToUser_to_phone_no">Phone No</label>\n\
<input maxlength="12" class="field" name="RecommendToUser[to_phone_no][]" id="RecommendToUser_to_phone_no" type="text"></div> <div class="clear"></div></div>\n\
 <p class="alignR"><a href="javascript:void(0)" id="addmoreFriend' + counter + '" onclick=removeFrienddetails(this.id);>-Remove</a></p></div>');

     }

     function removeFrienddetails(id) {
         $("#remove_" + id).remove();

     }
     $('#recommend_to_frd').click(function(e) {
         var isValid = true;
         $('.requiredfield').each(function() {
             if ($.trim($(this).val()) == '') {
                 var errorid = $('#' + this.id).next('div').attr("id");
                 $("#" + errorid).show();
                 isValid = false;

             }
             else if ($.trim($(this).val()) != '') {
                 var errorid = $('#' + this.id).next('div').attr("id");
                 $("#" + errorid).hide();
                 $("#errorAnchor").hide();
                 $('.email').each(function() {
                     var email = $('#' + this.id).val();
                     var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                     if (!regex.test(email)) {
                         var errorid = $('#' + this.id).next('div').next('div').attr("id");
                         $("#" + errorid).text('');
                         $("#" + errorid).text('This email is not valid.').show();
                         isValid = false;
                     }
                 });

             } else {
                 var errorid = $('#' + this.id).next('div').attr("id");
                 $("#" + errorid).hide();
                 $("#errorAnchor").hide();
             }
         });
         if (isValid == false)
             e.preventDefault();
         if (isValid == true) {
             jQuery.ajax({
                 'type': 'POST',
                 'url': "<?php echo Yii::app()->createAbsoluteUrl("RecommendToUser/SaveRecommendtoFreind"); ?>",
                 'data': $("#recommend-to-user-form").serialize(),
                 'beforeSend': function(jqXHR, settings) {
                     $("#AjaxLoader").show();
                 },
                 'success': function(data) {
                     $("#AjaxLoader").hide();
                     $("#frd_success").show();
                     $("#formResult").html("Your message has been sent successfully.");
                     $("#recommend-to-user-form").hide();
                 },
                 'cache': false
             });
         }


     });





</script>
